﻿using System;
using System.Collections.Generic;
using System.Text;

namespace Rarous.TexyNet {
  /// <summary>
  /// Reference.
  /// </summary>
  public class Reference {
    #region Fields
    private string _name;
    private string _url;
    private string _title;
    private Modifier _modifier;
    #endregion

    #region Constructors
    /// <summary>
    /// Konstruktor.
    /// </summary>
    /// <param name="name">Nazev reference.</param>
    /// <param name="url">Url reference.</param>
    public Reference(string name, string url)
      : this(name, url, String.Empty) {
    }

    /// <summary>
    /// Konstruktor.
    /// </summary>
    /// <param name="name">Nazev reference.</param>
    /// <param name="url">Url reference.</param>
    /// <param name="title">Text odkazu.</param>
    public Reference(string name, string url, string title)
      : this(name, url, title, String.Empty) {
    }

    /// <summary>
    /// Konstruktor.
    /// </summary>
    /// <param name="name">Nazev reference.</param>
    /// <param name="url">Url reference.</param>
    /// <param name="title">Text odkazu.</param>
    /// <param name="tooltip">ToolTip k odkazu.</param>
    public Reference(string name, string url, string title, string tooltip) {
      _name = name;
      _url = url;
      _title = title;
      _modifier = new Modifier(tooltip);
    }
    #endregion

    #region Properties
    /// <summary>
    /// Vraci nebo nastavuje nazev reference.
    /// </summary>
    public string Name {
      get {
        return _name;
      }
      set {
        _name = value;
      }
    }

    /// <summary>
    /// Vrací nebo nastavuje URL odkazu.
    /// </summary>
    public string Url {
      get {
        return _url;
      }
      set {
        _url = value;
      }
    }

    /// <summary>
    /// Vrací nebo nastavuje Text odkazu.
    /// </summary>
    public string Title {
      get {
        return _title;
      }
      set {
        _title = value;
      }
    }

    /// <summary>
    /// Vraci modifikator v textove podobe.
    /// </summary>
    public Modifier Modifier {
      get {
        return _modifier;
      }
    }

    /// <summary>
    /// Vraci vystupni pattern.
    /// </summary>
    protected virtual string OutputPattern {
      get {
        return "[{0}]: {1}{2}{3}";
      }
    }
    #endregion

    #region Object Members
    /// <summary>
    /// Vraci textovou podobu definice reference v Texy!
    /// </summary>
    /// <returns></returns>
    public override string ToString() {
      if (String.IsNullOrEmpty(Name) || String.IsNullOrEmpty(Url)) {
        return String.Empty;
      }
      string title = String.Empty;
      if (!String.IsNullOrEmpty(Title)) {
        title = " " + Title;
      }

      return String.Format(OutputPattern, Name, Url, title, Modifier).Trim();
    }
    #endregion
  }
}
